package com.banciyuan.bcywebview.base.helper.access;

import android.content.Context;

import com.banciyuan.bcywebview.utils.sp.SPConstant;
import com.banciyuan.bcywebview.utils.sp.SPHelper;
import com.banciyuan.bcywebview.utils.string.StringUtil;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.util.List;

import de.greenrobot.daoexample.model.UserAccess;

/**
 * Created by squall on 2017/6/30.
 */

public class UserAccessHelper {

    public static void updateUserAccess(Context mContext, String accessString) {
        SPHelper.putString(mContext, SPConstant.USER_ACCESS, SPConstant.USER_ACCESS, accessString);
    }

    /**
     * get the access of post img in comment
     * @param mContext
     * @return
     */
    public static boolean getReplyCommentAccess(Context mContext) {
        Gson gson = new Gson();
        String result = SPHelper.getString(mContext, SPConstant.USER_ACCESS, SPConstant.USER_ACCESS, "[]");
        List<UserAccess> ulist = gson.fromJson(result, new TypeToken<List<UserAccess>>() {
        }.getType());
        for (UserAccess u : ulist) {
            if (StringUtil.notNullEqual(u.getAccess(), "reply_comment") && u.isValue()) {
                return true;
            }
        }
        return false;
    }
}
